<template>
  <page-header-wrapper>
    <global-search ref="globalSearch" :list="searchList" @search="handleSearch" @reset="handleReset"> </global-search>
    <a-card :bordered="false">
      <s-table
        ref="table"
        size="default"
        :rowKey="(record, index) => index"
        :columns="columns"
        :data="loadData"
        :pagination="{ showTotal: (total) => `共 ${total} 条` }"
      >
        <span slot="index" slot-scope="text, record, index">{{ index + 1 }} </span>
      </s-table>
    </a-card>
  </page-header-wrapper>
</template>

<script>
import { STable, Ellipsis } from '@/components'
import { getQuarterStatementCategory } from '@/api/statementAndStatistics'
import moment from 'moment'
export default {
  components: {
    STable,
    Ellipsis
  },
  computed: {
    columns () {
      const { year, quarter } = this.queryParam
      return [
        {
          title: `${year}年度第${quarter}季度出文统计表`,
          align: 'center',
          children: [
            {
              title: `序号`,
              align: 'center',
              width: '80px',
              scopedSlots: { customRender: 'index' }
            },
            {
              title: `辖区`,
              align: 'center',
              dataIndex: 'XQ'
            },
            {
              title: '信息采集名称',
              align: 'center',
              children: [
                {
                  title: `新增符合`,
                  align: 'center',
                  dataIndex: 'XZFH',
                  sorter: (a, b) => a.XZFH - b.XZFH
                }, {
                  title: `新增不符合`,
                  align: 'center',
                  dataIndex: 'XZBFH',
                  sorter: (a, b) => a.XZBFH - b.XZBFH
                }, {
                  title: `变更`,
                  align: 'center',
                  dataIndex: 'BG',
                  sorter: (a, b) => a.BG - b.BG
                }, {
                  title: `退出`,
                  align: 'center',
                  dataIndex: 'TC',
                  sorter: (a, b) => a.TC - b.TC
                }
              ]
            },
            {
              title: `备注`,
              align: 'center'
            }
          ]
        }
      ]
    }
  },
  data () {
    return {
      searchList: [
        {
          label: '年度',
          fields: 'year',
          type: 'year',
          initialValue: moment().year(),
          props: {
            placeholder: '请选择年度'
          }
        },
        {
          label: '季度',
          fields: 'quarter',
          type: 'select',
          initialValue: moment().quarter(),
          props: {
            placeholder: '请选择季度',
            options: [
              {
                label: '第一季度',
                value: 1
              },
              {
                label: '第二季度',
                value: 2
              },
              {
                label: '第三季度',
                value: 3
              },
              {
                label: '第四季度',
                value: 4
              }
            ]
          }
        }
      ],
      queryParam: {
        Mode: 'QuarterStatementCategory',
        year: moment().year(),
        quarter: moment().quarter(),
        UserID: this.$store.getters.userid
      },
      // 加载数据方法 必须为 Promise 对象
      loadData: (parameter) => {
        const requestParameters = Object.assign({}, parameter, this.queryParam)
        return getQuarterStatementCategory(requestParameters).then((res) => res)
      }
    }
  },
  methods: {
    handleSearch (values) {
      Object.assign(this.queryParam, values)
      this.tableRefresh(true)
    },
    handleReset () {
      Object.assign(this.queryParam, {
        year: moment().year(),
        quarter: moment().quarter()
      })
      this.tableRefresh(true)
    },
    tableRefresh (refresh = false) {
      this.$refs.table.refresh(refresh)
    }
  }
}
</script>
<style scoped>
</style>
